define([
  'underscore',
  'views/View',
  'views/List',
  'views/media/ImagePreview',
  'collections/Collection',
//  'views/upload/UploadPreview',
  'hbs!template/users/uploaded-photo-list'
], function(_, View, List, ImagePreview, Collection, list_template){
  var ImageUploaded = ImagePreview.extend({
    flags: {
      check: true,
      progress: false,
      modal:false
    }
  });
  
  var ListUploadedView = List.extend({
    template: list_template,
    itemView: ImageUploaded,

    initList: function() {
      this.selection = new Collection();
      this.collection.bind("change:selected", this.updateSelection, this);
    },
    
    getSelected: function() {
      return this.selection.models;
      
    },

/*    renderList: function() {
      this.Logger.debug("RenderList");
      // Build pagination and the body template
      var pagination = this.collection.pagination;
      // TODO temp method for testing!
      console.log(this.template({pagination: pagination.info()}));
      $(this.el).html(this.template({pagination: pagination.info()}));
      var self = this;
      
      // Build the list
      var $list = this.$(".list");
      _.each(pagination.models(), function(item){
        if(self.selection.get(item)) {
          item.set({selected: true});
        }
        
        
	var itemView = new self.itemView({
	  model:	item,
	  collection: self.collection
	});
	$list.append(itemView.render().el);
      });
    },
*/
    updateSelection: function(model) {
      console.log("update selection");
      var selected = model.get('selected');
      if(selected) {
        this.selection.add(model);
      } else {
        this.selection.remove(model);
      }
      console.log("------------------------");
    }
  });

  return ListUploadedView;
});